<template>
<div>
    <div class="e-table billList">
        <div class="top">
            <div class="left">
                <div class="listTop">
                    <el-button
                        size="small"
                        class="btn-greenYellow"
                        @click="exportData"
                    >
                        导出</el-button
                    >
                </div>
            </div>
            <div class="right">
                <div class="right-div1">
                    <el-input
                        placeholder="请输入关键字"
                        size="small"
                        v-model="pagination.keyword"
                        @blur="search"
                    >
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="search"></i>
                    </el-input>
                </div>
                <div>
                    <el-button
                        size="small"
                        style="background: #2e61d7; color: #fff"
                        @click="heightSharch"
                        >高级搜索
                    </el-button>
                </div>
            </div>
        </div>
        <el-table
            ref="table"
            class="table"
            :data="tableData"
            border
            style="width: 100%"
            highlight-current-row
            height="0"
            v-sortTable="{ 'tableData': tableData, '_this': this, 'ref': 'table' }"
        >
            <el-table-column label="设备编号"
                class-name="blue-column"
                min-width="200"
                show-overflow-tooltip
            >
                <template slot-scope="{ row }" >
                    <span @click="tableDbShow(row)">{{row.equipmentNo}}</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="leaseType"
                label="设备来源"
                align="center"
                width="200"
            >
                 <template slot-scope="{ row }">
                    <span>{{ row.leaseType ? leaseTypeList.find(x=>x.value === row.leaseType).label : '' }}</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="equipmentName"
                label="设备名称"
                align="center"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="plateNo"
                label="车辆编号"
                align="center"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="specificationModel"
                label="规格型号"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
             <el-table-column
                prop="leasePrice"
                label="租赁单价（元）"
                width="150"
            >
            </el-table-column>
              <el-table-column
                prop="leaseAmount"
                label="租赁费用（元）"
                width="150"
            >
            </el-table-column>
            <el-table-column
                prop="equipmentState"
                label="设备状态"
                width="150"
            >
                <template slot-scope="{ row }">
                    <span>{{ row.equipmentState+'' && row.equipmentState !== null? equipStatus.find(x=>x.value == row.equipmentState).label : '' }}</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="accountState"
                label="台账状态"
                width="150"
            >
                <template slot-scope="{ row }">
                    <span>{{ row.accountState+'' && row.accountState !== null ? accountStatus.find(x=>x.value == row.accountState).label : '' }}</span>
                </template>
            </el-table-column>
             <el-table-column
                prop="useOrgName"
                label="使用单位"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="equipmentUnitName"
                label="所属机构"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
        </el-table>
        <ComPagination
            :total="totalPage"
            :pageSize.sync="pagination.limit"
            :currentPage.sync="pagination.page"
            @currentChange="listByEntity"
            @sizeChange="listByEntity"
            class="bottomSetting"
        />
    </div>
</div>
</template>

<script>
import request from '@/api/equip/equipAccount.js'
import ComPagination from '@/components/pagination/pagination.vue'
import { mapState } from 'vuex'
import { vueDom, debounce, downloadFile, advanceSearch } from '@/utils/common.js'
export default {
    data () {
        return {
            tableData: [],
            pagination: {
                'belongOrgId': '', //所属机构Id
                'equipmentName': '',
                'keyword': '',
                'limit': 20,
                'orgId': localStorage.getItem('searchOrgId'),
                'page': 1,
                'states': [], //台账状态
                'useId': '', //使用单位id
            },
            totalPage: 0, //总页数
            tableHeight: 0,
        }
    },
    components: {
        ComPagination
    },
    computed: {
        ...mapState({
            workStatus: state=>state.equip.equipData.workStatus,
            assessmentLevel: state=>state.equip.equipData.assessmentLevel,
            equipStatus: state => state.equip.equipData.equipStatus, //设备状态
            accountStatus: state => state.equip.equipData.accountStatus, //台账状态
            leaseTypeList: state => state.equip.equipData.leaseTypeList, //租赁类型
        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value === param)
                return obj.label
            }
        },
    },
    created () {
        this.getDicValue()
        this.getList()
    },
    mounted () {
        // table动态高度
        vueDom(
            () => {
                this.tableHeight = document.body.clientHeight - 170
            },
            () => {
                return $('table').length !== 0
            }
        )
        this.fn = () => {
            this.tableHeight = document.body.clientHeight - 170
        }
        window.onresize = debounce(this.fn)
    },
    methods: {
        //获取当前使用的字典
        getDicValue () {
            this.$store.dispatch('equip/setEquipStatus')//更新设备状态
        },
        getList () {
            request.leaseAccountList(this.pagination).then(res=>{
                this.tableData = res.list
                this.totalPage = res.totalCount
            })
        },
        //分页查询
        listByEntity () {
            this.getList()
        },
        //模糊搜索
        search () {
            this.getList()
        },
        //清空高级搜索的数据
        clearData () {
            this.pagination = {
                'belongOrgId': '', //所属机构Id
                'equipmentName': '',
                'keyword': '',
                'limit': 20,
                'orgId': '',
                'page': 1,
                'states': [], //台账状态
                'useId': '', //使用单位id
            }
            this.setSearchData({ equipSearchData: this.pagination })
        },
        heightSharch () {
            advanceSearch('/equipAccountHeightSearch?type=1').then(res => {
                this.pagination = res.equipSearchData
                this.getList()
                this.clearData()
            })
        },
        //导出
        exportData () {
            if(this.tableData.length === 0) {
                this.clientPop('err', '当前机构没有可导出的数据！')
                return
            }
            request.leaseAccountExport().then(res=>{
                downloadFile({ data: res, name: '租赁台账.xlsx' })
            })
        },
        //查看
        tableDbShow (row) {
            this.$router.push({
                path: '/leaseAccountShow',
                query: { billid: row.billId }
            })
        },
    }
}
</script>

<style lang="scss" scoped>
</style>
